✨ BCA JUL24 Batch ✨

Join Our WhatsApp Group

Anukasif Pic

4.3 - String Handling in C - MCQs

Interactive MCQs Quiz

Test your knowledge with these questions

1. What does the null character "\0" represent in a string in C?

2. Which function is used to find the length of a string in C?

3. What is the return value of the strlen() function when applied to an empty string?

4. Which function is used to copy one string to another in C?

5. Which function is used to concatenate two strings in C?

6. What is the return value of strcmp() if two strings are identical?

7. Which header file is required for using string functions like strlen(), strcpy(), and strcmp()?

8. If char s1[] = "hello"; and char s2[] = "world";, what does strcat(s1, s2); do?

9. Which of the following string functions compares two strings lexicographically?

10. If char s1[] = "abc"; and char s2[] = "ABC";, what does strcmp(s1, s2); return?

11. Which function can be used to safely copy a specified number of characters from one string to another?

12. What does the strcmp() function return if the first string is lexicographically smaller than the second?

13. What will strlen("hello world") return?

14. Which of the following strings will be stored correctly in memory?

15. Which function can be used to append a specific number of characters from one string to another?

16. What does strcpy() do with the null terminator \0 when copying a string?

17. What is the output of strcmp("apple", "banana")?

18. In C, strings are stored as arrays of characters terminated by which character?

19. Which of the following functions is not used for string comparison?

20. What will the function strcmp("apple", "apple") return?

21. Which function is used for string concatenation in C?

22. What does the strcat() function do?

23. What is the correct syntax of the strcat() function?

24. What will strlen("Hello World") return?

25. Which header file is needed for string functions like strcpy() and strlen()?

26. Which function is used to copy one string to another in C?

27. Which function is used to determine the length of a string in C?

28. In strcat(), the source string is:

29. What does the strlen() function return?

30. If char str[] = "C language";, what will strlen(str) return?

31. What is the output of strcpy(dest, src) if dest has a size smaller than src?

32. Which function compares two strings lexicographically?

33. What does strcmp() return if the first string is lexicographically smaller than the second?

34. What will strlen("") return?

35. Which string function returns the concatenated string?

36. What does strcpy(dest, src) do?

37. If char s[] = "apple";, what will strlen(s) return?

38. What will be the result of strcmp("apple", "apple")?

39. Which function is used to concatenate two strings in C?

40. What happens if strcmp() finds two identical strings?

41. What does a pointer store in C?

42. What is the primary use of pointers in C?

43. What does the * symbol represent in pointer declaration?

44. How do you declare a pointer to a string in C?

45. What will char *ptr = "Hello"; store in ptr?

46. Which of the following is true about pointers and arrays?

47. How do you access the value of a variable through a pointer?

48. What will *(ptr + 2) access in a string pointer ptr pointing to "Hello"?

49. How can you move to the next character in a string using a pointer?

50. Which of the following function uses pointers to pass variables by reference?

51. How does char *ptr = str; work in C?

52. What is the output of the following code?

                        char str[6] = "Hello";
                        char *ptr = str;
                        printf("%c", *(ptr+1));
                    

53. What does the expression ptr[2] mean if ptr is a pointer to a string?

54. What does char *ptr = "Hello"; do in memory?

55. Which operator is used to get the address of a variable in C?

56. What is the output of this code?

                        char str[6] = "World";
                        char *ptr = str;
                        while(*ptr != '\0') {
                            printf("%c", *ptr);
                            ptr++;
                        }
                    

57. Which function can dynamically allocate memory for a string?

58. Which of the following is true about pointer arithmetic in C?

59. What does *(ptr++) do?

60. Why is it necessary to use free() with dynamically allocated memory?